<template>
  <div class="table_header_btn_box">
    <div class="table_header_btn">
      <el-button type="text" class="btn_box" @click="downloadClick" :disabled="isDownloadBtn">
        <i class="el-icon-download icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.download') }} </span>
      </el-button>
      <el-button type="text" v-if="pageType != 'enterprise'" class="btn_box" @click="otherClick('copy')"
        :disabled="isCopyBtn">
        <i class="el-icon-document-copy icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.copy') }} </span>
      </el-button>
      <el-button type="text" v-if="pageType != 'enterprise'" class="btn_box" @click="moveClick" :disabled="isMoveBtn">
        <svg-icon icon-class="move" class="icon"></svg-icon>
        <span class="name">{{ $t('teamDoc.rightBtnList.move') }} </span>
      </el-button>
      <el-button type="text" class="btn_box" @click="deleteClick" :disabled="isDeleteBtn">
        <svg-icon icon-class="trash" class="icon"></svg-icon>
        <span class="name">{{ pageType != "enterprise" ? $t('teamDoc.rightBtnList.delete') :
          $t('teamDoc.rightBtnList.invalid') }}
        </span>
      </el-button>
      <el-button v-if="tableRowArray.length == 1" type="text" class="btn_box" @click="otherClick('collection')">
        <svg-icon v-if="tableRowArray[0].collection == '1'" icon-class="collect-fill" class="icon_size"></svg-icon>
        <svg-icon v-else icon-class="collect" class="icon_size"></svg-icon>
        <span class="name">{{ $t('teamDoc.rightBtnList.collect') }} </span>
      </el-button>
      <!-- 个人单个文件添加标签的操作 -->
      <el-button v-if="tableRowArray.length == 1 && pageType == 'self'" type="text" class="btn_box"
        @click="otherClick('label')">
        <i class="el-icon-collection icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.tags') }}</span>
      </el-button>
      <!-- 个人多个文件添加标签的操作 -->
      <el-button v-if="tableRowArray.length != 1 && pageType == 'self'" type="text" class="btn_box"
        @click="otherClick('label')">
        <i class="el-icon-collection icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.tags') }}</span>
      </el-button>
      <!-- 团队多个文件添加标签的操作 -->
      <el-button v-if="tableRowArray.length != 1 && pageType == 'team'" type="text" class="btn_box"
        @click="otherClick('teamLabel')">
        <i class="el-icon-collection icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.teamTags') }}</span>
      </el-button>

      <!-- 企业多个文件添加标签的操作 -->
      <el-button v-if="tableRowArray.length != 1 && pageType == 'enterprise'" type="text" class="btn_box"
        @click="otherClick('enterpriseLabel')">
        <i class="el-icon-collection icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.tagDocuments') }}</span>
      </el-button>
      <el-button type="text" v-if="pageType != 'enterprise'" class="btn_box" @click="otherClick('outEnjoy')"
        :disabled="isOutEnjoyBtn">
        <i class="el-icon-receiving icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.distribute') }}</span>
      </el-button>
      <el-button type="text" v-if="pageType != 'enterprise'" class="btn_box" @click="enjoyClick" :disabled="isShareBtn">
        <i class="el-icon-share icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.share') }}</span>
      </el-button>

      <el-button v-if="tableRowArray.length == 1" type="text" class="btn_box" @click="otherClick('detail')">
        <i class="el-icon-view icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.details') }}</span>
      </el-button>

      <el-button type="text" class="btn_box" @click="otherClick('exportBtn')" v-if="isFolderOnly">
        <i class="el-icon-upload2 icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.export') }}</span>
      </el-button>

      <el-button v-if="tableRowArray.length == 1 && tableRowArray[0].type == 'file'" type="text" class="btn_box"
        @click="otherClick('detail')">
        <svg-icon icon-class="history" class="icon" />
        <span class="name">{{ $t('teamDoc.rightBtnList.versions') }}</span>
      </el-button>
      <div v-if="pageType == 'self' || pageType == 'team'" class="btn_box">
        <el-dropdown @command="moreListCommand">
          <div class="btn_box">
            <i class="el-icon-more-outline"></i>
            <span class="name">{{ $t('teamDoc.rightBtnList.more') }}</span>
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item class="Dropdown_item_menu" v-if="pageType == 'self'" icon="el-icon-plus"
              command="submitFileToTeam">{{
                $t('teamDoc.rightBtnList.commitToTeam') }}</el-dropdown-item>
            <el-dropdown-item class="Dropdown_item_menu " icon="el-icon-plus" command="enterpriseLabel">
              {{ $t('teamDoc.rightBtnList.submitEnterprise') }}
            </el-dropdown-item>
            <el-dropdown-item v-if="isShowMenu() && this.tableRowArray.length == 1" class="Dropdown_item_menu_more"
              icon="el-icon-circle-plus-outline" command="joinTemplates">
              {{ $t('teamDoc.rightBtnList.joinTemplates') }}
              <i class="el-icon-caret-right"></i>
              <div class="info">
                <p @click="otherClick('templateLibrary')">{{ this.$t("teamDoc.rightBtnList.personalTemplateLibrary") }}
                </p>
                <p @click="otherClick('publicTemplateLibrary')">{{ this.$t("teamDoc.rightBtnList.commonTemplateLibrary")
                  }}</p>
              </div>
            </el-dropdown-item>
            <el-dropdown-item v-if="fileFerryHidden()" class="Dropdown_item_menu" icon="el-icon-sort"
              command="ferryFile">
              {{ $t("teamDoc.rightBtnList.inOut") }}
            </el-dropdown-item>

            <el-dropdown-item v-if="pageType == 'self'" class="Dropdown_item_menu" icon="el-icon-link "
              command="invitationEdit">
              {{ $t('teamDoc.rightBtnList.inviteCollaboration') }}
            </el-dropdown-item>

            <el-dropdown-item v-if="pageType == 'team' && this.tableRowArray[0].type == 'file'"
              class="Dropdown_item_menu" icon="el-icon-data-analysis " command="addTrain">
              {{ $t('teamDoc.rightBtnList.joinTrain') }}
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <el-button v-if="isFileLibrary" type="text" class="btn_box" @click="otherClick('fileLibrary')">
        <i class="el-icon-upload2" />
        <span class="name">{{ $t('teamDoc.rightBtnList.fileIntoStorage') }}</span>
      </el-button>
      <div v-if="pageType == 'enterprise'" class="btn_box">
        <el-dropdown @command="fileEnhanceCommand" trigger="click">
          <!-- <el-button type="text" class="filter-item dropdownBtn" size="small" icon="el-icon-tickets" :disabled="tableRowArray.length == 0">文件增强</el-button> -->
          <div class="btn_box">
            <svg-icon icon-class="floder" class="icon" />
            <span class="name">{{ $t('teamDoc.rightBtnList.fileEnhance') }}</span>
          </div>
          <el-dropdown-menu slot="dropdown">
            <div class="dropdown_menu">
              <el-dropdown-item class="Dropdown_item_menu" icon="el-icon-notebook-2" command="life">{{
                $t('teamDoc.rightBtnList.life') }}</el-dropdown-item>
              <el-dropdown-item
                v-if="tableRowArray.length == 1 && pageType == 'enterprise' && tableRowArray[0].type == 'folder'"
                class="Dropdown_item_menu" command="createTemp">
                <svg-icon icon-class="xiangmu1" class="icon_size icon_mr"></svg-icon>
                <span>{{ $t('teamDoc.rightBtnList.fileTemp') }}</span>
              </el-dropdown-item>
              <div v-if="$yuUtils.LicenseInfoFunc('yideng:list')">
                <!-- <el-dropdown-item class="Dropdown_item_menu" icon="el-icon-medal-1" command="safety">制定密级</el-dropdown-item> -->
                <el-dropdown-item v-if="tableRowArray.length == 1 && pageType == 'enterprise'"
                  class="Dropdown_item_menu" icon="el-icon-coin" command="metadata">
                  {{ $t('teamDoc.rightBtnList.metadata') }}
                </el-dropdown-item>
                <!-- <el-dropdown-item class="Dropdown_item_menu" >
                  
                </el-dropdown-item> -->
              </div>
            </div>
          </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown v-if="pageType == 'enterprise'" @command="moreListCommand" trigger="click">
          <div class="btn_box">
            <svg-icon icon-class="ai_chat3" class="icon_size icon_mr" />
            {{ $t('teamDoc.rightBtnList.aiFunction') }}
            <!-- <i class="el-icon-caret-right"></i> -->
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item class="Dropdown_item_menu">
              <svg-icon icon-class="gongzuozongjie" class="icon_size icon_mr" />
              <span>{{ $t('teamDoc.rightBtnList.aiSummarize') }}</span>
            </el-dropdown-item>
            <el-dropdown-item class="Dropdown_item_menu">
              <svg-icon icon-class="tiaocha" class="icon_size icon_mr" />
              <span>{{ $t('teamDoc.rightBtnList.aiAbstract') }}</span>
            </el-dropdown-item>
            <el-dropdown-item class="Dropdown_item_menu">
              <svg-icon icon-class="ai_chat3" class="icon_size icon_mr" />
              <span>{{ $t('teamDoc.rightBtnList.aiChat') }}</span>
            </el-dropdown-item>
            <el-dropdown-item class="Dropdown_item_menu item_border_bottom">
              <svg-icon icon-class="zhishichouqu" class="icon_size icon_mr" />
              <span>{{ $t('teamDoc.rightBtnList.aiExtract') }}</span>
            </el-dropdown-item>
            <el-dropdown-item class="Dropdown_item_menu item_border_bottom">
              <svg-icon icon-class="huiyi" class="icon_size icon_mr" />
              <span>{{ $t('teamDoc.rightBtnList.aiRead') }}</span>
            </el-dropdown-item>
            <el-dropdown-item class="Dropdown_item_menu">
              <svg-icon icon-class="xlsq-high-copy" class="icon_size icon_mr" />
              <span>{{ $t('teamDoc.rightBtnList.aiDrill') }}</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <!--  -->
      <el-button v-if="pageType == 'enterprise' && $store.state.settings.knowledge_base_state == '1'" type="text"
        class="btn_box" :disabled="isSyncAi" @click="otherClick('syncKnowledge')">
        <!-- <i class="el-icon-refresh icon"></i> -->
        <svg-icon icon-class="xlsq-high-copy" class="icon_size icon_mr" />
        <span class="name">{{ $t('teamDoc.rightBtnList.aiDrill') }}</span>
      </el-button>
    </div>
    <!-- 密级safety -->
    <el-dialog :title="$t('teamDoc.rightBtnList.securityLevel')" :visible.sync="dialogSafety" width="500px"
      :append-to-body="true" :close-on-click-modal="false" @close="cancelDialogSafetyclick">
      <el-form :model="formSafety">
        <el-form-item :label="$t('teamDoc.rightBtnList.securityLevel')">
          <el-select v-model="formSafety.grade" placeholder="请选择" style="width: 80%">
            <el-option :label="$t('teamDoc.rightBtnList.public')" value="公开"></el-option>
            <el-option :label="$t('teamDoc.rightBtnList.interior')" value="内部"></el-option>
            <el-option :label="$t('teamDoc.rightBtnList.secret')" value="秘密"></el-option>
            <el-option :label="$t('teamDoc.rightBtnList.confidential')" value="机密"></el-option>
            <el-option :label="$t('teamDoc.rightBtnList.topSecret')" value="绝密"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDialogSafetyclick">{{ $t('commen.cancel') }}</el-button>
        <el-button type="primary" @click="SureDialogSafetyClick">{{ $t('commen.confirm') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "table-header-btn",
  props: {
    pageType: {
      type: String,
      default: "" //enterprise:企业,team:团队,self:个人
    },

    tableRowArray: {
      //用于文件增强
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  components: {},
  data() {
    return {
      /*密级--------*/
      dialogSafety: false,
      formSafety: {
        grade: ""
      }
    };
  },

  computed: {
    //复制的权限
    isCopyBtn() {
      if (this.pageType == "enterprise") {
        return false;
      } else if (this.pageType == "team") {
        return !this.$yuUtils.documentsPermissionFunc(["copy"], this.$store.state.teamRole.myTeamFIleRoleList);
      } else {
        return false;
      }
    },
    //移动的权限
    isMoveBtn() {
      if (this.pageType == "enterprise") {
        return false;
      } else if (this.pageType == "team") {
        return !this.$yuUtils.documentsPermissionFunc(["move"], this.$store.state.teamRole.myTeamFIleRoleList);
      } else {
        return false;
      }
    },
    //删除的权限
    isDeleteBtn() {
      if (this.pageType == "enterprise") {
        return !this.$yuUtils.documentsPermissionFunc(["delete"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
      } else if (this.pageType == "team") {
        return !this.$yuUtils.documentsPermissionFunc(["delete"], this.$store.state.teamRole.myTeamFIleRoleList);
      } else {
        return false;
      }
    },
    //下载的权限
    isDownloadBtn() {
      if (this.pageType == "enterprise") {
        return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
      } else if (this.pageType == "team") {
        return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.teamRole.myTeamFIleRoleList);
      } else {
        return false;
      }
    },
    //分享的权限
    isShareBtn() {
      if (this.pageType == "enterprise") {
        return false;
      } else if (this.pageType == "team") {
        return !this.$yuUtils.documentsPermissionFunc(["share"], this.$store.state.teamRole.myTeamFIleRoleList);
      } else {
        return false;
      }
    },
    // 分发权限
    isOutEnjoyBtn() {
      if (this.pageType == "enterprise") {
        return false;
      } else if (this.pageType == "team") {
        return !this.$yuUtils.documentsPermissionFunc(["distribute"], this.$store.state.teamRole.myTeamFIleRoleList);
      } else {
        return false;
      }
    },
    // 同步到AI模型
    isSyncAi() {
      if (this.pageType == "enterprise") {
        return !this.$yuUtils.documentsPermissionFunc(["syncAi"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
      } else if (this.pageType == "team") {
        return false;
      } else {
        return false;
      }
    },
    // 归档入库的显示条件
    isFileLibrary() {
      let isShow = false;
      let res = this.tableRowArray.filter((item) => item.type == "folder");
      if (this.pageType == "enterprise" && this.tableRowArray.length > 0 && res.length == 0 && this.$yuUtils.LicenseInfoFunc("archives:list")) {
        isShow = true;
      }
      return isShow;
    },

    // 检查 tableRowArray 中的每一个元素是否都是 'folder',不是就不显示
    isFolderOnly() {
      return this.tableRowArray.every((item) => item.type === "folder");
    }
  },
  mounted() { },
  methods: {
    moveClick() {
      this.$emit("moveClick");
    },
    deleteClick() {
      //   if (this.pageType != "enterprise") {
      //     this.$emit("deleteClick");
      //   } else {
      //     this.$emit("getAbolishFile");
      //   }
      this.$emit("deleteClick");
    },
    enjoyClick() {
      this.$emit("enjoyClick");
    },
    downloadClick() {
      this.$emit("downloadClick");
    },

    otherClick(str) {
      // 这个方法在globalMixins.js文件里
      this.$emit("otherClick", str);
    },
    // 更多
    moreListCommand(command) {
      this.$emit("otherClick", command);
    },
    //文件增强
    fileEnhanceCommand(str) {
      // 密级
      if (str == "safety") {
        this.dialogSafety = true;
      } else {
        this.$emit("fileEnhanceCommand", str);
      }
    },
    /*密级*/
    // 密级取消按钮
    cancelDialogSafetyclick() {
      this.dialogSafety = false;
      this.formSafety.grade = "";
    },
    //密级确定按钮
    SureDialogSafetyClick() {
      this.$message.info("修改密级暂未开放");
      this.cancelDialogSafetyclick();
    },
    // 内外摆渡按钮显示判断
    fileFerryHidden() {
      if (this.$store.state.user.ferrySwitch && this.pageType == "self" && this.$yuUtils.vifpermissionRoles(["admin", "ferry:list"])) {
        return !false;
      } else {
        return !true;
      }
    },
    // 模板库菜单显示判断
    isShowMenu() {
      if (
        (this.tableRowArray[0].type == "file" && ["ppt", "excel", "docx"].indexOf(this.tableRowArray[0].suffix > -1)) ||
        this.pageType == "enterprise"
      ) {
        return true;
      } else {
        return false;
      }
    }
  }
};
</script>
<style scoped lang="scss">
.table_header_btn_box {
  // height: 34px;
}

.table_header_btn {
  height: 34px;
  display: flex;
  align-items: center;
  position: relative;
  z-index: 800;
  padding: 0;
}

.btn_box {
  display: flex !important;
  align-items: center !important;
  color: #666;
  font-size: 14px;
  margin-right: 6px;
  cursor: pointer;
  padding: 0;
  line-height: normal;

  .icon {
    color: #999;
    font-size: 15px;
    margin-top: 2px;
  }

  .name {
    margin-left: 6px;
  }

  &:hover {
    color: #6698ff;

    .icon {
      color: #6698ff;
    }
  }
}

.el-button.is-disabled.el-button--text {
  color: #c0c4cc;
  cursor: not-allowed;

  .icon {
    color: #c0c4cc;
  }

  &:hover {
    color: #c0c4cc;

    .icon {
      color: #c0c4cc;
    }
  }
}

.Dropdown_item_menu {
  padding-top: 5px !important;
  padding-bottom: 5px !important;
  font-size: 14px !important;

  &:hover {
    background-color: #f5f5f5 !important;
    color: #606266;
  }
}

.Dropdown_item_menu_more {
  position: relative;
  padding-top: 5px !important;
  padding-bottom: 5px !important;
  font-size: 14px !important;

  .info {
    display: none;
  }

  &:hover {
    .info {
      display: block;
      position: absolute;
      left: 120px;
      top: -50%;
      width: 100px;
      height: 100px;
      background-color: white;
      padding: 10px 0px;

      p {
        margin: 0;
        padding: 0;
        text-align: center;
        line-height: 35px;

        &:hover {
          background-color: #f5f5f5 !important;
          color: #606266;
        }
      }
    }

    background-color: #f5f5f5 !important;
    color: #606266;
  }
}

.item_border_bottom {
  border-bottom: 1px solid #eee;
}

.icon_mr {
  margin-right: 6px;
}
</style>
